﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SNSpirit.Domain.User;

namespace SNSpirit.Domain.Forum
{
    /// <summary>
    /// Post
    /// 帖子中的每个回复（包括首楼）
    /// </summary>
    public class Post : LazyDomainEntity
    {
        public Post(ForumService service)
            : base(new LoadAction<LazyDomainEntity>(o =>
                {
                    service.UpdateCore(o as Post);
                }), true)
        {
            if (service == null)
                throw new ArgumentNullException("service");
            this.Service = service;
        }

        public ForumService Service { get; private set; }

        #region Title

        private ContentValue _Title;

        /// <summary>
        /// Title
        /// </summary>
        public ContentValue Title
        {
            get { return this._Title; }
            set
            {
                if (this._Title != value)
                {
                    this._Title = value;
                    this.OnPropertyChanged("Title");
                }
            }
        }

        #endregion Title

        #region Author

        private UserEntity _Author;

        /// <summary>
        /// Author
        /// </summary>
        public UserEntity Author
        {
            get { return this._Author; }
            set
            {
                if (this._Author != value)
                {
                    this._Author = value;
                    this.OnPropertyChanged("Author");
                }
            }
        }

        #endregion Author

        #region Content

        private ContentValue _Content;

        /// <summary>
        /// Content
        /// </summary>
        public ContentValue Content
        {
            get { return this._Content; }
            set
            {
                if (this._Content != value)
                {
                    this._Content = value;
                    this.OnPropertyChanged("Content");
                }
            }
        }

        #endregion Content

        #region PublishTime

        private DateTime? _PublishTime;

        /// <summary>
        /// PublishTime
        /// </summary>
        public DateTime? PublishTime
        {
            get { return this._PublishTime; }
            set
            {
                if (this._PublishTime != value)
                {
                    this._PublishTime = value;
                    this.OnPropertyChanged("PublishTime");
                }
            }
        }

        #endregion PublishTime

        public virtual void Update()
        {
            this.Load();
        }

        public virtual void UpdateAsync()
        {
            this.LoadAsync();
        }
    }
}